using System;
using UnityEditor;
using UnityEngine;
using Yoozoo.Gameplay.City;

namespace Yoozoo.Gameplay.Hanging.Editor
{
    [CustomEditor(typeof(HangingAirWallMgr))]
    public class HangingAirWallMgrEditor : UnityEditor.Editor
    {
        private HangingAirWallMgr _hangingAirWallMgr;
        private void OnEnable()
        {
            _hangingAirWallMgr = target as HangingAirWallMgr;
        }

        public override void OnInspectorGUI()
        {
            if (_hangingAirWallMgr.airWallGroups!=null)
            {
                for (int i = 0; i < _hangingAirWallMgr.airWallGroups.Count; i++)
                {
                    if (i % 4 == 0)
                    {
                        GUILayout.BeginHorizontal();
                    }

                    var gname = _hangingAirWallMgr.airWallGroups[i].groupName;
                    if (GUILayout.Button(gname))
                    {
                        _hangingAirWallMgr.UnlockWallGroup(gname);
                    }

                    if (i % 4 == 3 || i == _hangingAirWallMgr.airWallGroups.Count - 1)
                    {
                        GUILayout.EndHorizontal();
                    }
                }
            }

            if (GUILayout.Button("规范缩放"))
            {
                var airWalls= _hangingAirWallMgr.GetComponentsInChildren<AirWallDefiner>();
                foreach (var airWall in airWalls)
                {
                    Vector3 scale = airWall.transform.localScale;
                    airWall.WallCollider.transform.localScale = scale;
                    airWall.transform.localScale = Vector3.one;
                }
            }
            
            base.OnInspectorGUI();
        }
    }
}